<template>
  <div class="hello">
    <el-date-picker
      @change="selectDate"
      v-model="value1"
      type="daterange"
      range-separator="至"
      start-placeholder="开始日期"
      end-placeholder="结束日期">
    </el-date-picker>
    <el-button type="primary" @click="thisWeek">本周</el-button>
    <el-button type="primary" @click="lastWeek">上周</el-button>
    <div style="padding:20px">
      <el-button type="primary" @click="createReport">生成报表</el-button>
      <el-link :href="url" v-if="linkShow">下载链接</el-link>
    </div>
     
  </div>
</template>

<script>
import dayjs from 'dayjs'
import axios from 'axios'
export default {
  name: 'HelloWorld',
  props: {
    msg: String
  },
  data(){
    return{
      url:"",
      linkShow:false,
      value1: ''
    }
  },
  created(){
   var now = dayjs()
   console.log('last week start:'+now.startOf('week').subtract(13, 'day').format('YYYY-MM-DD'))//本周
   console.log('last week end:'+now.endOf('week').subtract(13, 'day').format('YYYY-MM-DD'))//本周
   console.log('start:'+now.startOf('week').subtract(6, 'day').format('YYYY-MM-DD'))//本周
   console.log('end:'+now.endOf('week').subtract(6, 'day').format('YYYY-MM-DD'))//本周
   this.value1=[now.startOf('week').subtract(13, 'day').format('YYYY-MM-DD'),now.endOf('week').subtract(13, 'day').format('YYYY-MM-DD')]
  },
  methods:{
    selectDate(){
      console.log('date:'+this.value1)
    },
    thisWeek(){
      var now = dayjs()
      this.value1=[now.startOf('week').subtract(6, 'day').format('YYYY-MM-DD'),now.endOf('week').subtract(6, 'day').format('YYYY-MM-DD')]
    },
    lastWeek(){
      var now = dayjs()
      this.value1=[now.startOf('week').subtract(13, 'day').format('YYYY-MM-DD'),now.endOf('week').subtract(13, 'day').format('YYYY-MM-DD')]
    },
    createReport(){
       axios.get('http://193.187.116.167:3030/dkdk',{       // 还可以直接把参数拼接在url后边
        params:{
            startTime:this.value1[0],
            endTime:this.value1[1]
        }
    }).then((res)=>{
        console.log('res:',res)
        this.url='http://193.187.116.167:3000/output/'+res.data.output_file
        console.log('url:'+this.url)
    }).catch(function (error) {
        console.log(error);
    });
      this.linkShow=true
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h3 {
  margin: 40px 0 0;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>
